from ..arch import Arch, Cluster


def c2c_score(cluster1: Cluster, cluster2: Cluster) -> float:
    a = len(cluster1 & cluster2)
    b = max(len(cluster1), len(cluster2))
    return a / b


def c2c_cvg(recovered: Arch, ground_truth: Arch, threshold: float = 0.5) -> float:
    sim_C = 0
    for _, cluster2 in ground_truth.items():
        score = 0
        for _, cluster1 in recovered.items():
            score = max(c2c_score(cluster1, cluster2), score)
        if score > threshold:
            sim_C += 1
    return sim_C / len(ground_truth)
